//
// Created by 86155 on 2025/4/15.
//

#ifndef LLVM_FETARGETMACHINE_H
#define LLVM_FETARGETMACHINE_H

#include<optional>
#include "llvm/Target/TargetMachine.h"
#include "FeSubtarget.h"
#include "MCTargetDesc/FeMCTargetDesc.h"

namespace llvm {
class FeTargetMachine : public LLVMTargetMachine {
  std::unique_ptr<TargetLoweringObjectFile> TLOF;
  FeSubtarget Subtarget;
public:
  // 构造函数
  FeTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
                  StringRef FS, const TargetOptions &Options,
                  std::optional<Reloc::Model> RM,
                  std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
                  bool JIT);

  const FeSubtarget *getSubtargetImpl(const Function &F) const override {
    return &Subtarget;
  }

  const FeSubtarget *getSubtargetImpl() const { return &Subtarget;     }

  TargetLoweringObjectFile *getObjFileLowering() const override {   //必须重写
    return TLOF.get();
  }

  // Pass Pipeline Configuration
  TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
};
}

#endif // LLVM_FETARGETMACHINE_H
